package com.rafaelGarcia.eLibreria.db;

import java.util.Properties;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

public class GestorDB {
	
	private static GestorDB gestor = null;	
	private static SessionFactory sessionFactory = null;  
	
	private GestorDB(){
    	ServiceRegistry serviceRegistry = null;
    	
    	Configuration configuration = new Configuration();  
		configuration.configure();  
		  
		Properties properties = configuration.getProperties();
		  
		serviceRegistry = new ServiceRegistryBuilder().applySettings(properties).buildServiceRegistry();          
		sessionFactory = configuration.buildSessionFactory(serviceRegistry);	
	}
	
	private static void iniciar(){
		if(gestor == null){
			gestor = new GestorDB();
		}
	}
	
	public static SessionFactory getSessionFactory(){	
		iniciar();
		
		return sessionFactory;
	}	
}
